import { Component, OnInit, Input } from '@angular/core';
import { AppGlobalService } from '../../shared/service/app-global.service';

@Component({
    selector: 'app-case',
    templateUrl: './case.component.html',
    styleUrls: ['./case.component.scss'],
})
export class CaseComponent implements OnInit {

    @Input() tagData: any;

    caseData = [];

    constructor(
        private appGlobalService: AppGlobalService
    ) {
    }
    defaultImg = 'assets/img/default_img.png';
    ngOnInit() {
        const len = this.tagData.data.data.length;
        if (len > 0) {
            for (let i = 0; i < len; i++) {
                const v = this.tagData.data.data[i];
                if (v.imageUrl.url !== undefined && v.imageUrl.url !== "") {
                    let url = v.imageUrl.url ;
                    url = url.replace(';', '');
                    v.imageUrl.url = url;
                } else {
                    v.imageUrl = { url: this.defaultImg };
                }
                this.caseData.push(v);
            }
        }
    }


    go(obj) {
        const pageParams = {
            pageId: obj.target,
            params: obj.params,
            sessionId: localStorage.getItem('sessionId')
        };
        this.appGlobalService.goToForward(pageParams);
    }

    getNgStyle(str) {
        try {
            return JSON.parse(str);
        } catch (error) {
            return {};
        }
    }

}
